<div class="layui-fluid layui-anim febs-anim" id="febs-chicken" lay-title="修改鸡信息">
    <div class="layui-row febs-container">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body febs-table-full">
                    <form class="layui-form layui-table-form" lay-filter="user-table-form">
                        <div class="layui-row">
                            <div class="layui-col-md10">
                            </div>
                            <div class="layui-col-md2 layui-col-sm12 layui-col-xs12 table-action-area">
<!--                                <div class="layui-btn layui-btn-sm layui-btn-primary table-action" id="query">-->
<!--                                    <i class="layui-icon">&#xe848;</i>-->
<!--                                </div>-->
<!--                                <div class="layui-btn layui-btn-sm layui-btn-primary table-action" id="reset">-->
<!--                                    <i class="layui-icon">&#xe79b;</i>-->
<!--                                </div>-->
                                <div class="layui-btn layui-btn-sm layui-btn-primary table-action action-more"
                                     shiro:hasAnyPermissions="chicken:export">
                                    <i class="layui-icon">&#xe875;</i>
                                </div>
                            </div>
                        </div>
                    </form>
                    <table lay-filter="chickenTable" lay-data="{id: 'chickenTable'}"></table>
                    <div class="layui-form-item febs-hide">
                        <label class="layui-form-label febs-form-item-require">批次ID：<span id="batchesId">[[${batchesId}]]</span></label>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/html" id="chicken-option">
    <span shiro:lacksPermission="chicken:update">
        <span class="layui-badge-dot febs-bg-orange"></span> 无权限
    </span>
    <a lay-event="edit" shiro:hasPermission="chicken:update"><i
            class="layui-icon febs-edit-area febs-blue">&#xe7a4;</i></a>
</script>
<script data-th-inline="none" type="text/javascript">
    layui.use(['dropdown', 'jquery', 'laydate', 'form', 'table', 'febs', 'treeSelect'], function () {
        var $ = layui.jquery,
            laydate = layui.laydate,
            febs = layui.febs,
            form = layui.form,
            table = layui.table,
            treeSelect = layui.treeSelect,
            dropdown = layui.dropdown,
            $view = $('#febs-chicken'),
            $query = $view.find('#query'),
            $reset = $view.find('#reset'),
            $searchForm = $view.find('form'),
            sortObject = {field: 'createTime', type: null},
            tableIns,
            createTimeFrom,
            createTimeTo;
        form.render();
        initTable();

        dropdown.render({
            elem: $view.find('.action-more'),
            click: function (name, elem, event) {
                var checkStatus = table.checkStatus('chickenTable');
                if (name === 'export') {
                    var params = $.extend(getQueryParams(), {field: sortObject.field, order: sortObject.type});
                    params.pageSize = $view.find(".layui-laypage-limits option:selected").val();
                    params.pageNum = $view.find(".layui-laypage-em").next().html();
                    febs.download(ctx + 'user/excel', params, '用户信息表.xlsx');
                }
            },
            options: [{
                name: 'export',
                title: '导出Excel',
                perms: 'chicken:export'
            }]
        });

        table.on('tool(chickenTable)', function (obj) {
            var data = obj.data,
                layEvent = obj.event;
            data.sex = parseInt(data.sex);
            data.weight = parseInt(data.weight);
            if (layEvent === 'edit') {
                febs.post(ctx + 'chicken/update', data, function () {
                    febs.alert.success('修改鸡信息成功');
                    $query.trigger('click');
                });
            }
        });


        $query.on('click', function () {
            // var params = $.extend(getQueryParams(), {field: sortObject.field, order: sortObject.type});
            tableIns.reload({where: params, page: {curr: 1}});
        });

        $reset.on('click', function () {
            $searchForm[0].reset();
            treeSelect.revokeNode('dept');
            sortObject.type = 'null';
            createTimeTo = null;
            createTimeFrom = null;
            tableIns.reload({where: getQueryParams(), page: {curr: 1}, initSort: sortObject});
        });

        function initTable() {
            tableIns = febs.table.init({
                elem: $view.find('table'),
                id: 'chickenTable',
                url: ctx + 'chicken/list/' + $view.find("#batchesId").html(),
                cols: [[
                    // {type: 'checkbox'},
                    {field: 'chickenId', title: '编号'},
                    {field: 'weight', title: '毛重', minWidth: 100, edit: 'text', templet: function (d) {
                        if (d.weight == null){
                            return "";
                        }
                            return d.weight + "kg";
                        }},
                    {field: 'sex', title: '鸡公母', edit: 'text', templet: function (d) {
                        if (d.sex == 0){
                            return "公鸡";
                        }else if (d.sex == 1){
                            return "母鸡";
                        }else if ($.trim(d.sex) == "公鸡"){
                            d.sex = 0;
                            return "公鸡";
                        }else if ($.trim(d.sex) == "母鸡"){
                            d.sex = 1;
                            return "母鸡";
                        }
                        return "";
                    }},
                    {title: '确定', toolbar: '#chicken-option', width: 80}
                ]]
            });
        }

        function getQueryParams() {
            // var createTime = $searchForm.find('input[name="createTime"]').val();
            // if (createTime) {
            //     createTimeFrom = createTime.split(' - ')[0];
            //     createTimeTo = createTime.split(' - ')[1];
            // }
            // return {
            //     createTimeFrom: createTimeFrom,
            //     createTimeTo: createTimeTo,
            //     username: $searchForm.find('input[name="username"]').val().trim(),
            //     status: $searchForm.find("select[name='status']").val(),
            //     sex: $searchForm.find("select[name='sex']").val(),
            //     mobile: $searchForm.find("input[name='mobile']").val().trim(),
            //     deptId: $searchForm.find("input[name='dept']").val().trim(),
            //     invalidate_ie_cache: new Date()
            // };
        }
    })
</script>